
#ifndef ACEL_ADDR_HPP
#define ACEL_ADDR_HPP

namespace   acel
{

#ifndef AF_ANY
#define AF_ANY  (-1)
#endif


/**
 * @class Addr
 *
 * @brief Defines the base class for the "address family independent" address format.
 */
class   Addr
{
public:
    // = Initialization and termination methods.
    /// Initializes instance variables.
    Addr (int type = -1, int size = -1)
        :   _addr_type(type), _addr_size(size)
    {}

    /// Destructor.
    virtual ~Addr (void) {}

    // = Get/set the size of the address.

    /// Return the size of the address.
    int getSize (void) const { return _addr_size; }

    /// Sets the size of the address.
    void setSize (int size)  { _addr_size = size; }

    // = Get/set the type of the address.

    /// Get the type of the address.
    int getType (void) const { return _addr_type; }

    /// Set the type of the address.
    void setType (int type)  { _addr_type = type; }

    /// Return a pointer to the address.
    virtual void *getAddr (void) const { return 0; }

    /// Set a pointer to the address.
    virtual void setAddr (void *, int len) {}

    // = Equality/inequality tests
    /// Check for address equality.
    bool operator == (const Addr &sap) const
    {
      return (sap._addr_type == this->_addr_type &&
              sap._addr_size == this->_addr_size   );
    }

    /// Check for address inequality.
    bool operator != (const Addr &sap) const
    {
      return (sap._addr_type != this->_addr_type ||
              sap._addr_size != this->_addr_size   );
    }

    /// Initializes instance variables.
    virtual void base_set (int type, int size)
    {
        _addr_type = type;
        _addr_size = size;
    }

    /// Wild-card address.
    static const Addr sap_any;

    /// Returns a hash value.  This should be overwritten by a subclass
    /// that can produce a better hash value.
    virtual unsigned long hash (void) const { return 0; }

protected:
    /// e.g., AF_UNIX, AF_INET, AF_SPIPE, etc.
    int _addr_type;

    /// Number of bytes in the address.
    int _addr_size;
    
};  // Addr

}   // namespace acel

#endif  //ACEL_ADDR_HEPP
